package de.bensoft.jrail.client.com;

import java.util.ArrayList;
import java.util.List;

import javax.inject.Inject;
import javax.inject.Singleton;

import de.bensoft.jrail.business.entity.TrackplanSegment;
import de.bensoft.jrail.business.service.TrackplanService;
import de.bensoft.jrail.client.com.interfaces.LI100;

@Singleton
public class DeflectorComunicator {

	@Inject
	TrackplanService service;
	
	@Inject
	LI100 li100;
	
	private List<DeflectorInstance> lstInstances;
	
	public DeflectorComunicator() {
		lstInstances = new ArrayList<DeflectorInstance>();
	}
	
	public DeflectorInstance getInstanceByData(TrackplanSegment data) {
		DeflectorInstance instance = null;
		
		for(DeflectorInstance inst : lstInstances) {
			if(inst.getTrackplanSegment().equals(data))
				return inst;
		}
		
		instance = new DeflectorInstance(this, data, service);
		return instance;
	}
	
	
	public void sendCommand(byte[] cmd) {
		li100.sendCommand(cmd);
	}
}
